//
//  Sky72SlideMainViewController.m
//  Sky72
//
//  Created by ladaka on 13. 9. 16..
//  Copyright (c) 2013년 ladaka Inc. All rights reserved.
//

#import "Sky72SlideMainViewController.h"
#import "Sky72MainViewCell.h"

@interface Sky72SlideMainViewController ()

@end

@implementation Sky72SlideMainViewController
@synthesize arrTableViewList;

#define FUNCTION_LOG        NSLog(@"%s [Line %d]", __FUNCTION__, __LINE__)

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
       
    // Do any additional setup after loading the view from its nib.
    self.arrTableViewList = [[NSMutableArray alloc] init];
    
    // MY SKY72
    NSMutableArray *arrMySky72 = [[NSMutableArray alloc] init];
    [arrMySky72 addObject:@"더미"];
    
    NSMutableDictionary *arrDicList1 = [[NSMutableDictionary alloc]init];
    [arrDicList1 setObject:arrMySky72 forKey:@"data"];
    [arrDicList1 setObject:@"더미" forKey:@"section"];
    [self.arrTableViewList addObject:arrDicList1];
    
    // 예약하기
    NSMutableArray *arrReservation = [[NSMutableArray alloc] init];
    [arrReservation addObject:@"정기예약"];
    [arrReservation addObject:@"빠른예약"];
    
    NSMutableDictionary *arrDicList2 = [[NSMutableDictionary alloc]init];
    [arrDicList2 setObject:arrReservation forKey:@"data"];
    [arrDicList2 setObject:@"예약하기" forKey:@"section"];
    [self.arrTableViewList addObject:arrDicList2];
    
    // SKY72 코스보기
    NSMutableArray *arrSkyCourse = [[NSMutableArray alloc] init];
    [arrSkyCourse addObject:@"하늘코스"];
    [arrSkyCourse addObject:@"레이크코스"];
    [arrSkyCourse addObject:@"클래식코스"];
    
    NSMutableDictionary *arrDicList3 = [[NSMutableDictionary alloc]init];
    [arrDicList3 setObject:arrSkyCourse forKey:@"data"];
    [arrDicList3 setObject:@"SKY72 코스보기" forKey:@"section"];
    [self.arrTableViewList addObject:arrDicList3];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidUnload {
    [super viewDidUnload];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (IBAction)onClickHome:(id)sender {
    [self.revealSideViewController pushViewController:self onDirection:PPRevealSideDirectionNone animated:YES];
}

- (IBAction)onClickLogin:(id)sender {
}

#pragma mark - UITableViewDelegate, UITableViewDataSource

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    FUNCTION_LOG;
    NSArray *nib;
    UIView *view;
    
    if (section == 0) {  // MY SKY72
        nib = [[NSBundle mainBundle] loadNibNamed:@"Sky72MainViewHeader" owner:self options:nil];
        view = [nib objectAtIndex:0];
    } else {
        nib = [[NSBundle mainBundle] loadNibNamed:@"Sky72MainViewHeader" owner:self options:nil];
        view = [nib objectAtIndex:1];
        UILabel *lbl = (UILabel *)[view viewWithTag:99];
        
        if([self.arrTableViewList count] > 0) {
            NSLog(@"section %@", [[self.arrTableViewList objectAtIndex:section]objectForKey:@"section"]);
            lbl.text = [[self.arrTableViewList objectAtIndex:section]objectForKey:@"section"];
        }
    }
    return view;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    FUNCTION_LOG;
    if ([arrTableViewList count] > 0 && [arrTableViewList objectAtIndex:section] != nil && section > 0) {
        NSLog(@"numberOfRowsInSection = %d",[[[arrTableViewList objectAtIndex:section] objectForKey:@"data"] count]);
        
        return [[[arrTableViewList objectAtIndex:section] objectForKey:@"data"] count];
    }
    return 0;
}

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {  // MY SKY72
        return 300;
    }
    
    return 22;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    if ([arrTableViewList count] > 0) {
        return [arrTableViewList count];
    }
    return 0;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"Sky72MainViewCell";
    
    Sky72MainViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Sky72MainViewCell" owner:nil options:nil];
        cell = [nib objectAtIndex:0];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    if([self.arrTableViewList count] > 0 && [self.arrTableViewList count] > indexPath.section) {
        NSMutableArray *arrContent = [[self.arrTableViewList objectAtIndex:indexPath.section] objectForKey:@"data"];
        cell.lblCellLabel.text = [arrContent objectAtIndex:indexPath.row];
    }
    
    return cell;
}

// 아이템 선택시 호출
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    FUNCTION_LOG;
//    NSMutableArray *arrItem = [[self.arrTableViewList objectAtIndex:indexPath.section] objectForKey:@"data"];
}
@end
